<?php
namespace hotel\modules\apiadmin\controllers;
use hotel\common\utils\Tool;
use hotel\modules\apiadmin\models\RoomFacilitiesType;
use \Yii;

class RoomFacilitiesTypeController extends CoreController
{

	public function actionRoomFacilitiesTypeList()
	{
		$page_size = $this->request('page_size',10);
		$page = $this->request('page',1);
		$list = RoomFacilitiesType::find()->offset($page_size*($page-1))->limit($page_size)->asArray()->all();
		$counts = RoomFacilitiesType::find()->count();
		$data['list'] = $list;
		$data['pageInfo'] = [
			'count' => $counts,
			'pageSize' => $page_size,
			'currPage' => $page,
			'tatalPage' => ceil($counts/$page_size),
		];
		return Tool::showRes([0, '酒店设施类型列表'],$data);
	}

	/*
		修改
	*/
	public function actionRoomFacilitiesTypeEdit()
	{
		$id = $this->request('id');
		$model = new RoomFacilitiesType;
		if($id) $model = $model::findOne($id);
		$model->name = $this->request('name');
		$model->icon_url = $this->request('icon_url');
		$model->create_time = date('Y-m-d H:i:s');
		if($model->save()) {
			return Tool::showRes([0, '操作成功']);
		}
		return Tool::showRes([400, '操作失败']);
	}


	public function actionAllRoomFacilitiesTypeList()
	{
		$list = RoomFacilitiesType::find()->asArray()->all();
		return Tool::showRes([0, '酒店设施类型列表'],$list);
	}
}